<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@include file="include.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="js/metroui/js/jquery.dataTables.min.js"></script>
</head>
<body>
<div class="input-control text" data-role="input" style="float:right;">
<input type="text" name="search" id="extra_search"><button class="button"><span class="mif-search"></span></button>
</div>
<div class="input-control select">
<select id="setlib" name="libraryid"></select></div> <button id="b1" class="button">确定</button>

<div class="input-control select">
<select id="selectFileClass" name="classid"></select> </div><button id="b2" class="button">确定</button>

<button id="b3" class="button">重置搜索</button>

<table class="table striped hovered dataTable border bordered" id="dataTables-1" style="width:100%;">
                <thead>
                <tr>
                    <th class="text-left">Fileid</th>
                    <th class="text-left">Filename</th>
					<th class="text-left">Uploadtime</th>
					<th class="text-left">操作</th>
                </tr>
                </thead>

                <tbody>
                </tbody>
            </table>
            <!--  
            <button class="button primary" id="b1">Get List</button>
               <a href="download.action">test_download</a>
               -->
    <script type="text/javascript">
	
    $(document).ready(function(){
    function ChangeSearch(){
    		   var ss=$("#extra_search").val();
				table1.ajax.url(encodeURI("testjson.action?search="+ss)).load();
    	   }
    	 

   	$("#extra_search").blur(function(){
		
   		ChangeSearch();      		    
	});
   	$("#extra_search").focus(function(){
   		$("#extra_search").keydown(function(e){ 
   			if(e.keyCode==13){ 
   				ChangeSearch();
   			}
   			
   		});
   		
   	});
	



	var table1=$("#dataTables-1").DataTable( {
        "processing": true,
        "ordering": false, 
        "searching":false,
        serverSide: true,
        ajax:{
			url:"testjson.action"
			//"type": "GET"
			//data:"search="+$("#extra_search").val()
			},
     
        	//dataSrc: 'result'

    	"oLanguage": {
    		"sLengthMenu": "每页显示 _MENU_ 条记录",
    		"sZeroRecords": "抱歉， 没有找到",
    		"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
    		"sInfoEmpty": "没有数据",
    		"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
    		"oPaginate": {
    		"sFirst": "首页",
    		"sPrevious": "前一页",
    		"sNext": "后一页",
    		"sLast": "尾页"
    		},
    		"sZeroRecords": "没有检索到数据"
    	},
    	
    	
    columns: [ 
    	{data:"fileid"},
    	
    	{data:"filename"},
    	{data:"uploadtime.time",render:function(data){
    		
    		return UnixToDate(data);
    	}
    	},
    	{"defaultContent":"<button class='button primary block-shadow-info'>下载</button><button class='button success block-shadow-success' >修改</button>"}
    	]

	 }
    );

    $('#dataTables-1 tbody').on('click', '.primary', function () {

    	 var id=$(this).parent().parent().children("td").get(1).innerHTML; 

    	 window.location.href=encodeURI("download.action?dl_fileName="+id);
    	 
    	 
    } );
    $('#dataTables-1 tbody').on('click', '.success', function () {
    	var fileid=$(this).parent().parent().children("td").get(0).innerHTML;
    	var filename=$(this).parent().parent().children("td").get(1).innerHTML;
    	$("#fileid").val(fileid);
    	$("#fn").val(filename);
    	alert($("#fileid").val());
    	$("#filename").val(filename);
    	
    	metroDialog.open('#dialog');
   	 
   	 
   } );
    
	$("#b1").click(function(){
		var lib=$("#setlib").val();
		//alert(lib);
		table1.ajax.url(encodeURI("searchByLibrary.action?libraryid="+lib)).load();
	});
	$("#b2").click(function(){
		var cl=$("#selectFileClass").val();
		//alert(cl);
		table1.ajax.url(encodeURI("listFileByClass.action?classid="+cl)).load();
	});
	
	$("#b3").click(function(){
		$("#extra_search").val("");
		ChangeSearch();
	});
	
	$.get("listLibrary.action",function(data){
		
		for(var i=0;i<data.data.length;i++){
		$("#setlib").append("<option value='"+data.data[i].libraryid+"'>"+data.data[i].libraryname+"</option>");
		$("#l1").append("<option value='"+data.data[i].libraryid+"'>"+data.data[i].libraryname+"</option>");
		}
	});
	
	$.get("fileclass.action", function(c, status) {
		
		for(var i=0;i<c.fileclass.fileclass.length;i++){
		$("#selectFileClass").append("<option value='"+c.fileclass.fileclass[i].classid+"'>"+c.fileclass.fileclass[i].classname+"</option>");
		$("#c1").append("<option value='"+c.fileclass.fileclass[i].classid+"'>"+c.fileclass.fileclass[i].classname+"</option>");
		}
	});
   	});
    	
   

    
    function UnixToDate(unixTime) {
        var date=new Date(unixTime);
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds(); 
    	
        return Y+M+D+h+m+s;
    }


    </script>
    
 <div data-role="dialog" data-close-button="true" data-overlay="true" data-overlay-color="op-dark"
 data-overlay-click-close="true" data-type="info"  id="dialog"
 class="padding10"
 >
    <h1>修改文件属性</h1>
    <p>
        	文件名修改包括后缀名
    </p>
    <form action="updateFile.action" method="post">
    <div class="input-control text"><p>文件ID</p>
    <input type="text" id="fileid" name="update.fileid" readonly>
    </div>
    <div class="input-control text"><p>原文件名</p>
    <input type="text" id="fn" name="formername" readonly>
    </div>
        <br/><br/><br/><br/>
    <div class="input-control text"><p>设置新文件名</p>
    <input type="text" id="filename" name="update.filename">
    </div>
   
    <div class="input-control select">
     <p>选择类</p>
     <select id="c1" name="update.classid">
     </select>
    </div>
    <br/><br/><br/>
    <br/>
    <div class="input-control select">
    <p>选择库</p>
        <select id="l1" name="update.libraryid">
     	</select>
    </div>
    
    
    
    <div class="input-control select">
    <p>是否共享</p>
    <select name="update.share">
      	<option value="1">共享</option>
    	<option value="0">不共享</option>
    </select>
    </div>
    
    <div class="input-control select">
    <p>是否允许下载</p>
    <select name="update.download">
    <option value="1">允许下载</option>
    <option value="0">不允许下载</option>
    </select>
    </div>
    <br/><br/><br/><br/>
    <button type="submit" class="button info">提交</button>
	
   
    
    </form>
    
</div>

    	
    
</body>
</html>